#!/bin/bash

HOMENAME=`who -m | awk -F " " '{print $1}'`
#echo "卸载kylin-settings......"
#dpkg -P --force-all kylin-settings

#echo "开始下载升级包......" 
#rm /var/cache/apt/archives/*.deb 
#rm /usr/share/kylin-update-desktop/install 

#if [ ! -f "/usr/share/kylin-update-desktop/install" ];then
#    /usr/bin/python /usr/share/kylin-update-desktop/main.py 
#fi
#line=`cat /usr/share/kylin-update-desktop/install`
#apt-get --force-yes -y install -d $line


#echo "Uninstall the kernel package......" 
#dpkg -P --force-all kylin-general-desktop-kernel 
#dpkg -P --force-all kylin-general-desktop-kernel-headers 

#echo "install the kernel package......" 
#dpkg -i --force-all /usr/share/kylin-update-desktop/packg/kylin-headers-deskt*deb 
#dpkg -i --force-all /usr/share/kylin-update-desktop/packg/kylin-image-desktop-generic*deb 


#echo "卸载冲突包...." 
#dpkg -P --force-all fonts-droid-fallback libcheese-gtk23 libcheese7 

echo "install package......" 
cd /usr/share/kylin-update-desktop/packg/ 
#检测用户有没有备份还原包来决定需不需要升级备份还原
#backup=`dpkg -l|grep yhkylin-backup-tools`
#if [ ! "$backup" ];then
#    rm yhkylin-backup-tools_*deb
#fi

UCF_FORCE_CONFFNEW=YES  dpkg -i --force-all  ./*deb

# 获取升级是否正常完成
echo $? > /tmp/install-status

#echo "安装kylin-settings......"
#dpkg --force-all -i  /usr/share/kylin-update-desktop/kylin-settings*.deb



#echo "update initrd....."   
#mkinitramfs -o /boot/initramfs.img-4.4.58-20170818.kylin.5.desktop-generic  4.4.58-20170818.kylin.5.desktop-generic
#rm -rf /boot/initramfs.img
#ln -s initramfs.img-4.4.58-20170818.kylin.5.desktop-generic  /boot/initramfs.img

#echo "update grub....." 
#update-grub
#sed "s/menuentry 'Kylin 4.0-2SP1 .*' --class /menuentry 'Kylin 4.0-2SP1 4.4.13-20161128.kylin.5.desktop+' --class /" -i  /boot/grub/grub.cfg

#echo "特殊处理....." 
#dpkg -i --force-all system-config-printer_1.5.7+20160812-0kord9k4_all.deb
#bash /usr/share/kylin-update-desktop/kylin_4.0.2_security_install.sh
dpkg --configure -a

#sed -i 's#GOVERNOR="ondemand"#GOVERNOR="performance"#g' /etc/init.d/cpufrequtils
#systemctl enable cpufrequtils
#systemctl disable ondemand

#echo "认证文件备份和升级..."
#if [ ! -d "/etc/.kyinfo.d/" ]; then
#    mkdir /etc/.kyinfo.d/
#fi
#if [ -f "/usr/share/kylin-update-desktop/.kyinfo" ]; then
#    mv /etc/.kyinfo /etc/.kyinfo.d/`date +%Y-%m-%d_%H:%M:%S`
#    rm /etc/LICENSE
#    cp /usr/share/kylin-update-desktop/.kyinfo /etc/.kyinfo
#    cp /usr/share/kylin-update-desktop/LICENSE /etc/LICENSE
#fi


#su - `who -m | awk '{print $1}'` -c "mate-panel --reset"
#echo "卸载自己....." 
mv /usr/share/kylin-update-desktop/lsb-release /etc/
dpkg -P --force-all kylin-update-desktop
